package com.company;
import java.util.Random;
import java.util.Scanner;

public class GuessNumber {

    public static void main(String[] args) {
        //实现一轮游戏结束后玩家可以通过选择决定再玩一局还是结束游戏的功能
        while(true) {
            System.out.println("----------------");
            System.out.println("请输入1开始游戏");
            System.out.println("请输入0退出游戏");
            System.out.println("----------------");
            Scanner sca = new Scanner(System.in);
            int start = sca.nextInt();

            switch(start) {

                case 0:

                    System.out.println("已退出游戏");
                    System.exit(0);

                    break;

                case 1:

                    System.out.println("以开始游戏");
                    System.out.println();
                    System.out.println("我想好了一个数你猜吧");
                    Random r = new Random();
                    int num = r.nextInt(100);

                    int cs = 1;
                    int time = 7;

                    while(true) {
                        time--;

                        Scanner s = new Scanner(System.in);
                        int guess = s.nextInt();

                        if(cs==7) {
                            System.out.println("都7次了还没猜到，太笨了");
                            break;
                        }

                        if(num==guess) {
                            System.out.println("你猜对了哒");
                            break;
                        }
                        else if(num>=guess) {
                            System.out.println("猜小了，你还有"+time+"次机会");
                            cs++;
                            continue;
                        }
                        else if(num<=guess) {
                            System.out.println("猜大了，你还有"+time+"次机会");
                            cs++;
                            continue;
                        }

                    }



                    break;

                default:
                    System.out.println("请输入正确的字符");
                    break;
            }
        }

    }
}
